/**
 * @description: 常用组件全局注册
 * @fileName: register
 * @author: xsz
 * @date: 2022/9/20-16:07
 * @version: V1.0.0
 **/
import { title } from '@/config'
import * as lodash from 'lodash'
import { Decrypt, Encrypt } from '@/utils/decrypt'
import { setLocalStorage, getLocalStorage } from '@/utils/storage'
import store from '@/store'
import { getAccessToken } from '@/utils/accessToken'
import CsPage from '@/components/Pagination/index'
import CsDialog from '@/components/Dialog/index'
import CsSearch from '@/components/Search/index'
import CsImageViewer from '@/components/ImageViewer/index'
import CsDrawer from '@/components/Drawer/index.vue'
import CountDown from '@/components/CountDown/index'
import CsMessages from '@/components/Message/index'
const accessToken = store.getters['user/accessToken']
import moment from 'moment'
import 'moment/locale/zh-cn'
import PageHeader from '@/components/PageHeader/index.vue'
import BaseCard from '@/components/BaseCard/index.vue'
import ELSegmented from '@/components/ELSegmented/index.vue'
import Editor from '@/components/Editor/index.vue'
import ConfirmPop from '@/components/ConfirmPop/index.vue'
const install = (Vue, opts = {}) => {
  /* 全局accessToken */
  Vue.prototype.$baseAccessToken = () => {
    return accessToken || getAccessToken()
  }
  /* 全局标题 */
  Vue.prototype.$baseTitle = (() => {
    return title
  })()

  /* 全局Message */
  Vue.prototype.$baseMessage = CsMessages
  /* 全局加密处理*/
  // 解密
  Vue.prototype.$baseDecrypt = Decrypt
  // 加密
  Vue.prototype.$baseEncrypt = Encrypt

  Vue.prototype.$setLocalStorage = setLocalStorage
  Vue.prototype.$getLocalStorage = getLocalStorage

  Vue.prototype.$moment = moment

  /* 全局TableHeight */
  Vue.prototype.$baseTableHeight = (formHeight) => {
    let height = window.innerHeight
    const paddingHeight = 270
    if (typeof formHeight === 'number') {
      height = height - paddingHeight - formHeight
    } else {
      height = height - formHeight
    }
    return height
  }
  // 导出保存文件
  /* 全局lodash */
  Vue.prototype.$baseLodash = lodash
  /* 全局事件总线 */
  Vue.prototype.$baseEventBus = new Vue()

  /* 全局组件 */
  Vue.component('cs-page', CsPage)
  Vue.component('cs-search', CsSearch)
  Vue.component('cs-dialog', CsDialog)
  Vue.component('cs-image-viewer', CsImageViewer)
  Vue.component('cs-drawer', CsDrawer)
  Vue.component('count-down', CountDown)
  Vue.component('page-header', PageHeader)
  Vue.component('base-card', BaseCard)
  Vue.component('el-segmented', ELSegmented)
  Vue.component('prompt-editor', Editor)
  Vue.component('confirm-pop', ConfirmPop)
}

if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

export default install
